package com.hbter630.change.controller.api;

import com.hbter630.change.entity.User;
import com.hbter630.change.service.UserService;
import com.hbter630.change.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Title: ApiUserCotroller
 * @Author 笑霸fianl
 * @Package com.hbter630.change.controller.api
 * @Date 2023/5/27 14:01
 * @描述: 前台登录接口
 */
@RestController
@RequestMapping("/api")
@Api(tags = "前台用户接口")
@Slf4j
public class ApiUserController {

    @Autowired
    private UserService userService;

    @PostMapping("/passport/login")
    @ApiOperation(notes = "登录",value = " 登录", httpMethod = "POST", response = Result.class)
    public Result login(@RequestBody User user, HttpServletRequest request){

        log.info("\n 登录的信息 {}",request.getRequestURI());
        log.info("\n 登录的信息 {}",user);
        Result login = userService.login(user, request);

        return login;
    }

    @GetMapping("/info")
    @ApiOperation(notes = "用户详情",value = " 用户详情", httpMethod = "GET", response = Result.class)
    public Result info(){

        log.info("\n===/info");
        return userService.checkInfo();
    }

    /**
     * 退出
     */
    @GetMapping("loginout")
    public Result loginOut(){
        return userService.loginOut();
    }


}
